package com.z996.spring6.service.impl;

import com.z996.spring6.dao.SexDao;
import com.z996.spring6.dao.UserDao;
import com.z996.spring6.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.logging.Logger;

/**
 * 简述:<br>
 * 用户业务实现类
 *
 * @Author zfh18
 * @Date 2024-03-01 14:21
 * @Version 1.0
 **/
@Service
public class UserServiceImpl implements UserService {

        /*
    // set 注入
    private UserDao userDao;

    @Autowired
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
    */
    /*
    // 构造器注入
    private UserDao userDao;

    @Autowired
    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }
    */
 /*
    // 形参注入

    private UserDao userDao;

    public UserServiceImpl(@Autowired UserDao userDao) {
        this.userDao = userDao;
    }
*/

    // 当有参数的构造方法只有一个时，@Autowired注解可以省略。
//    private UserDao userDao;
//
//    public UserServiceImpl(UserDao userDao) {
//        this.userDao = userDao;
//    }

    //    属性注入
    @Autowired
    private UserDao userDao;

    // @Autowired注解和@Qualifier注解联合
    @Autowired
    @Qualifier("sexDaoImpl2")
    private SexDao sexDao;

    // @Resource 根据name注入
    @Resource(name = "sexDaoImpl1")
    private SexDao sexDao1;

    // 当@Resource注解使用时没有指定name的时候，还是根据name进行查找，这个name是属性名。
    @Resource
    private SexDao sexDaoImpl2;
    Logger logger = Logger.getLogger(getClass().getName());

    @Override
    public void add() {
        sexDao1.add();
        sexDao.add();
        userDao.add();
        logger.info("service ...");
    }
}
